//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System;
using System.Collections.Generic;
using System.Text;
using WCSFContrib.PageFlow;

namespace WCSFContrib.PageFlow.Xml.Tests.Mocks
{
	public class MockPageFlow : IPageFlow
	{
		#region IPageFlow Members

#pragma warning disable 0067
		public event EventHandler<PageFlowAbortedEventArgs> Aborted;

		public event EventHandler<PageFlowEventArgs> Started;

		public event EventHandler<PageFlowEventArgs> Completed;

        public event EventHandler<PageFlowEventArgs> Suspended;
        
        public event EventHandler<PageFlowEventArgs> Resumed;

#pragma warning restore 0067
        private PageFlowStatus _status = PageFlowStatus.NotStarted;
		private Page _currentPage;
		private Guid _id = Guid.NewGuid();

		public Page CurrentPage
		{
			get { return _currentPage; }
			set
			{
				_currentPage = value;
			}
		}

        private bool abortCalled;

        public bool AbortCalled
        {
            get { return abortCalled; }
        }

        private bool suspendCalled;

        public bool SuspendCalled
        {
            get { return suspendCalled; }
        }

        private bool resumeCalled;

        public bool ResumeCalled
        {
            get { return resumeCalled; }
        }
        
        private bool startCalled;

        public bool StartCalled
        {
            get { return startCalled; }
        }

		private IPageFlowDefinition _definition; 
		
		public IPageFlowDefinition Definition
		{
			get { return _definition; }
		}

		public Guid Id
		{
			get { return _id; }
		}

		public PageFlowStatus Status
		{
            get { return _status; }
		}

        public System.Collections.ObjectModel.ReadOnlyCollection<string> Transitions
		{
			get { throw new NotImplementedException("The method or operation is not implemented."); }
		}

        public PageFlowState UserData
		{
            get { throw new NotImplementedException("The method or operation is not implemented."); }
		}

		public void Abort(bool redirectToAbortPage)
		{
			abortCalled = true;
            if (Aborted != null)
                Aborted(this, new PageFlowAbortedEventArgs(this.Id));
		}

		public bool CanRedirectTo(string pageName)
		{
			if(_definition.Constrained && pageName != CurrentPage.Name)
			{
				return false;
			}
			else
			{
				return true;
			}
		}

        public void Navigate(string transitionName)
		{
			throw new NotImplementedException("The method or operation is not implemented.");
		}

        public void RedirectToCurrentPage()
		{
            throw new NotImplementedException("The method or operation is not implemented.");
		}

		public void SetCurrentPage(string pageName)
		{
			CurrentPage = _definition.GetPage(pageName);
		}

		public void Start()
		{
            startCalled = true;
            if (Started != null)
                Started(this, new PageFlowEventArgs(this));

            _status = PageFlowStatus.Running;
		}

		public void Suspend()
		{
            suspendCalled = true;
            if (Suspended != null)
                Suspended(this, new PageFlowEventArgs(this));

            _status = PageFlowStatus.Suspended;
		}

        public void Resume()
        {
            resumeCalled = true;
            if (Resumed != null)
                Resumed(this, new PageFlowEventArgs(this));

            _status = PageFlowStatus.Running;
        }

        public void Complete()
		{
			throw new NotImplementedException("The method or operation is not implemented.");
		}

        public void Next()
		{
            throw new NotImplementedException("The method or operation is not implemented.");
		}

		#endregion

        public MockPageFlow() : this (new MockConstrainedPageFlowDefinition())
        {
        }

		public MockPageFlow(IPageFlowDefinition definition)
		{
			_definition = definition;
		}        
	}
}
